/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package remotetest;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import sun.java2d.opengl.OGLContext;

/**
 *
 * @author prasath
 */
public class WPClient {

    private static XmlRpcClientConfigImpl config;
    private static XmlRpcClient client;



    public static void main(String args[]){
        try {
            config = new XmlRpcClientConfigImpl();
            config.setServerURL(new URL("http://localhost/wordtrunk/xmlrpc.php"));
  
            client = new XmlRpcClient();
            client.setConfig(config);
            wp_createUser();


            

        } catch (MalformedURLException ex) {
            System.out.println(ex);
        }

        
    }

    private static void wp_getPostFormats() {
        try {
            Vector params1 = new Vector();
            params1.add(1);
            params1.add("admin");
            params1.add("admin");

            System.out.println(params1);

            Object recentPosts = client.execute("wp.getPostFormats", params1);
            System.out.println(recentPosts);

        } catch (XmlRpcException ex) {
            System.out.println(ex);
        }
    }

    private static void wp_createUser() {
        try {
            Vector params1 = new Vector();
            params1.add(1);
            params1.add("admin");
            params1.add("admin");

            HashMap params = new HashMap();
            params.put("username", "sharmila");
            params.put("email", "sharmila@yahoo.com");
            params.put("firstname", "sharmi");
            params.put("lastname", "prasath");
            params.put("password", "admin123");

            params1.add(params);
            params1.add(false);

            System.out.println(params1);

            Object results = client.execute("wp.newUser", params1);
            System.out.println(results);

        } catch (XmlRpcException ex) {
            System.out.println(ex);
        }
    }

    private static void sayHello() {
        try {
            Vector params1 = new Vector();

            Object results = client.execute("demo.sayHello", params1);
            System.out.println(results);

        } catch (XmlRpcException ex) {
            System.out.println(ex);
        }
    }

    private static void  mw_newpost() {
        try {
            Vector params1 = new Vector();
            params1.add(1);
            params1.add("admin");
            params1.add("admin");

            HashMap params = new HashMap();
            params.put("title", "earlier check");
            params.put("description", "earlier check");
            params1.add(params);
            params1.add(false);

            System.out.println(params1);

            Object recentPosts = client.execute("metaWeblog.newPost", params1);
            System.out.println("draft posted successfully");

        } catch (XmlRpcException ex) {
            System.out.println(ex);
        }
    }


    private static void editCategories() {
        try {
            Vector params1 = new Vector();
            params1.add(1);
            params1.add(" wordtrunk");
            params1.add("admin");
            params1.add(4);

            HashMap params = new HashMap();
            params.put("name", "pundayanid");
            params.put("description", "i,m fucked up");

            params1.add(params);

            System.out.println(params1);
            Object result = client.execute("wp.editCategory", params1);
            System.out.println(result);
            //System.out.println(recentPosts);

        } catch(Exception ex) {
            System.out.println(ex);
        }
    }

    private static void mw_editPost() {
        try {
            Vector params1 = new Vector();
            params1.add(30);
            params1.add("admin");
            params1.add("admin");

            HashMap params = new HashMap();
            params.put("title", "keyword patch");
            params.put("description", "check whether patch is successful");
            params.put("mt_keywords", "");

            params1.add(params);
            params1.add(true);

            System.out.println(params1);
            Object result = client.execute("metaWeblog.editPost", params1);

            System.out.println(result);
            //System.out.println(recentPosts);

        } catch(Exception ex) {
            System.out.println(ex);
        }
    }
}
